package com.ruoyi.eam.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.eam.mapper.EamTypeMapper;
import com.ruoyi.eam.doman.EamType;
import com.ruoyi.eam.service.IEamTypeService;

/**
 * 资产类型Service业务层处理
 *
 * @author ruoyi
 * @date 2024-06-18
 */
@Service
public class EamTypeServiceImpl implements IEamTypeService
{
    @Autowired
    private EamTypeMapper eamTypeMapper;

    /**
     * 查询资产类型
     *
     * @param typeId 资产类型主键
     * @return 资产类型
     */
    @Override
    public EamType selectEamTypeByTypeId(Long typeId)
    {
        return eamTypeMapper.selectEamTypeByTypeId(typeId);
    }

    /**
     * 查询资产类型列表
     *
     * @param eamType 资产类型
     * @return 资产类型
     */
    @Override
    public List<EamType> selectEamTypeList(EamType eamType)
    {
        List<EamType> list = eamTypeMapper.selectEamTypeList(eamType);
        List<EamType> typeList = new ArrayList<>();
        for (EamType type : list) {
            if(type.getParentId() == null){
                typeList.add(type);
            }
        }
        return typeList;
    }

    /**
     * 新增资产类型
     *
     * @param eamType 资产类型
     * @return 结果
     */
    @Override
    public int insertEamType(EamType eamType)
    {
        eamType.setCreateTime(DateUtils.getNowDate());
        return eamTypeMapper.insertEamType(eamType);
    }

    /**
     * 修改资产类型
     *
     * @param eamType 资产类型
     * @return 结果
     */
    @Override
    public int updateEamType(EamType eamType)
    {
        return eamTypeMapper.updateEamType(eamType);
    }

    /**
     * 批量删除资产类型
     *
     * @param typeIds 需要删除的资产类型主键
     * @return 结果
     */
    @Override
    public int deleteEamTypeByTypeIds(Long[] typeIds)
    {
        return eamTypeMapper.deleteEamTypeByTypeIds(typeIds);
    }

    /**
     * 删除资产类型信息
     *
     * @param typeId 资产类型主键
     * @return 结果
     */
    @Override
    public int deleteEamTypeByTypeId(Long typeId)
    {
        return eamTypeMapper.deleteEamTypeByTypeId(typeId);
    }
}
